To filter at multiple node levels in an XML document while creating a document which displays the returned data.
XML Files can have nodes, children nodes, grand-children nodes, and an unlimited amount of levels after that. Not only that, but values and attributes can be stored at each node level including the root level, so it may be necessary to filter at several node levels. Unfortunately we don’t have any XML files this complex lying around, so we will be demonstrating this concept in a rather simple manner, but combining this tutorial with the previous XPath Wizard tutorials, you should have all the knowledge you need to make any level of complex multi-level filters in XML documents, the only limiting factor will be how much scratch paper you have to draw all the trees of data!
This tutorial builds on fundamentals learned in the other XPath Wizard tutorials, so we’ll be starting with the template made in XPath - Part 4: Filtering with Variable Values. If you don’t have that template, it is shown below and step-by-step instructions on creating are available in the previous XPath Tutorials.
First, open the XPath Wizard by selecting the ForEach tag and clicking Wizard under the AutoTag ribbon.
Now we’ll add a sub-node. We have already applied a filter to the top level, but by adding a sub-node we can now apply additional conditions to this level. We won’t be applying any conditions here, but now you can see how it can be done. Close the XPath Wizard when you are done with this.
Now, we have a different set of data selected. Instead of Orders, we have OrderDetails selected, so we need to change what data is displayed. Change the first column name to Product and the third to Quantity.
As part of changing what data is displayed, we need to change the out tags as well. Here we’ll change the 1st out tag to ProductID and the 3rd to Quantity (using the Data tree as always). The 2nd tag needs to be changed too, but we no longer have a Shipper ID to display
You might remember before we filtered the ShipVia node so that only one ShipperID is shown. Well this is beneficial to us now because instead of displaying the ShipVia node, we can simply display the $(ShipperID) variable we created before. Change the 2nd out tag’s data to the ShipperID via the Data tree.
Finally, generate the document and view the results! There is a lot of power in the feature demonstrated here, but you might not always find that it is necessary. Keep filters simple in the beginning. If you need a complex filter like shown here, you will know.
You have completed this tutorial. We recommend taking a look at the OData - Part 1: Basic Selection tutorial next!